nameList = #()

--replace geometry with objects to get groups as well, having trouble copying groups as there is something funny that happens 
--with the position / rotation
for obj in geometry where(obj.parent == undefined) do
(
	if(findItem nameList obj.name == 0) do
	(
		append nameList obj.name
	)
)


for objName in nameList do
(
	currentSelection = #()
	for obj in objects where (obj.name == objName and obj.parent == undefined) do
	(
		append currentSelection obj
	)
	
	select currentSelection

	if currentSelection.count > 1 do
	(
		original = currentSelection[1]
		for p=2 to currentSelection.count do --should use do instead of then, its faster when not expecting an else
		(
			
				currentObj = currentSelection[p]
				maxops.clonenodes original cloneType:#instance offset:[0,0,0] newNodes:&newobj
				newObj.name = original.name
				
				newObj.rotation = inverse currentObj.transform.rotation -- crazyness with rotations, you retrieve rotation in one coordinate system
																							--but you set it in another
																							-- http://forums.cgsociety.org/archive/index.php/t-95006.html
				newObj.position = currentObj.position

		)
		deselect original
		delete $
	)
)